<template>
  <div>
    <el-autocomplete
      :disabled="getbol"
      v-model="choosedp"
      placeholder="请输入设备名称"
      :fetchSuggestions="searcheq"
      @select="selecteq"
      style="width:100%;"
      clearable
      @clear="clearchoosedp"
    ></el-autocomplete>
  </div>
</template>

<script>
export default {
  props: {
    itempersonid: Object,
    disabled: Number,
    isself: Boolean,
  },
  data() {
    return {
      ts: this.newStore(),
      eqList: [],
      choosedp: '',
      fzrid: '',
      getbol: false,
    };
  },
  watch: {
    choosedp(newval) {
      if (newval == '') {
        this.$emit('update:selecteqid', '');
      }
    },
  },
  created() {
    if (this.isself) {
      this.fzrid = localStorage.getItem('pid');
    }
    this.geteqList();
  },
  mounted() {
    if (this.itempersonid) {
      this.choosedp = this.itempersonid.ep_ename;
    }
    if (this.disabled == 2) {
      this.getbol = true;
    }
  },
  methods: {
    clearchoosedp() {
      this.$emit('update:selecteqid', '');
    },
    // 获取设备列表
    geteqList() {
      this.eqList = [];
      const req = {
        handle: 'DD5D108B99FC12B72DC0B97F927BBE3D1A8639331D9DCC49',
        fzrid: this.fzrid,
        start: '0',
        limit: '100000',
      };
      this.spost(this.ts, '/mainservlet', req).then((ts) => {
        // console.log(ts.d.data, "00000000");

        for (let index = 0; index < ts.d.data.operation1.length; index += 1) {
          const a = {};
          a.value = `${ts.d.data.operation1[index].hash.ep_ename} - ${ts.d.data.operation1[index].hash.managenum}`;
          a.id = ts.d.data.operation1[index].hash.id;
          a.verifiytime = ts.d.data.operation1[index].hash.verifiytime;
          this.eqList.push(a);
        }
      });
    },
    // 搜索经办人
    searcheq(queryString, cb) {
      const results = queryString
        ? this.eqList.filter(this.createStateFilter(queryString))
        : this.eqList;

      clearTimeout(this.timeout);
      this.timeout = setTimeout(() => {
        cb(results);
      }, 1000 * Math.random());
    },
    createStateFilter(queryString) {
      return eqList => eqList.value.indexOf(queryString) > -1;
    },
    // 选择经办人后
    selecteq(val) {
      // console.log(val, "909090");
      this.$emit('update:selecteqid2', 'val');
      this.$emit('update:selecteqid', val);
    },
  },
};
</script>

<style>
</style>
